package com.costeaalex.MIDlets.remote.screens;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import com.costeaalex.MIDlets.remote.BlueMIDlet;
import com.costeaalex.MIDlets.remote.communication.CommunicationManager;

public class ScreenConnected implements CommandListener
	{
	
	public List commands;
	private Command cmBack;
	private Command cmSelect;
	private BlueMIDlet midlet;
	private CommunicationManager cM;
	private String results="";
	
	public ScreenConnected(CommunicationManager connManager, BlueMIDlet midl)
		{
		
		cM=connManager;
		midlet=midl;
		
		commands = new List("Connected", List.IMPLICIT);
		commands.insert(0, "Send", null);
		commands.insert(1, "Receive", null);
		commands.insert(2, " ", null);
			
		cmBack=new Command("Back", Command.BACK, 1);
		cmSelect=new Command("Select", Command.SCREEN, 1);
		
		commands.addCommand(cmBack);
		commands.addCommand(cmSelect);
		commands.setCommandListener(this);
		}
	//midlet.serviceselected(selected);

	public void commandAction(Command c, Displayable d)
		{
		int sI;
		
		if(c==cmBack)
			{
			midlet.displayManager.returnToParent();
			}
		
		if(c==cmSelect)
			{
			sI=commands.getSelectedIndex();
			switch(sI)
				{
				case 0:{cM.send(2);break;}
				case 1:{
						results+="_"+cM.receive();
						commands.set(2, results, null);
						break;
						}
				}
			}
		}

	}
